describe("App.api_accounts in SG", function() {

    describe("_buildAccountList", function() {

        it("accountType is product and productGroup is DDA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "DDA"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.DDAAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is STMT", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "STMT"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.STMTAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is STMT", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "TIME"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.TIMEAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is PTIME and productCode is not DDA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "CCA",
                        subProductCode: "100",
                        productGroup: "PTIME"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.PTIMENotDDAAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is PTIME and productCode is DDA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "PTIME"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.PTIMEAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is STIME", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "STIME"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.STIMEAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is PASS", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "PASS"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.PASSAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is SEC and productCode is SXA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "SXA",
                        subProductCode: "100",
                        productGroup: "SEC"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.SXAAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is SEC and productCode is not SXA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "SEC"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.SECAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is UNT and productCode is ISA and subProductCode is IS", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "ISA",
                        subProductCode: "IS",
                        productGroup: "UNT"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.UNTInvAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is UNT and productCode is ISA and subProductCode is IP", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "ISA",
                        subProductCode: "IP",
                        productGroup: "UNT"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.UNTInvAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is UNT and productCode is not ISA", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "UNT"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.UNTAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is ELN", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "ELN"
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.ELNAccount).toBeTruthy();
        });

        it("accountType is product and productGroup is others", function() {
            var response = {
                productListResponse: {
                    productList: [{
                        localCurrentBalance: 100.12,
                        productCode: "DDA",
                        subProductCode: "100",
                        productGroup: "XXX"
                    }, ],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.productList, 'product');

            expect(accountListObj.totalBalance).toEqual('100.12');
            expect(accountListObj.list[0] instanceof App.HaveAccount).toBeTruthy();
        });

        it("accountType is loan", function() {
            var response = {
                productListResponse: {
                    loanList: [{
                        "currentBalance": 1887.72
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.loanList, 'loan');

            expect(accountListObj.totalBalance).toEqual('1887.72');
            expect(accountListObj.list[0] instanceof App.LoanAccount).toBeTruthy();
        });

        it("accountType is card", function() {
            var response = {
                productListResponse: {
                    cardList: [{
                        "currentBalance": 1887.72
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.cardList, 'card');

            expect(accountListObj.totalBalance).toEqual('1887.72');
            expect(accountListObj.list[0] instanceof App.CardAccount).toBeTruthy();
        });


        it("accountType is others", function() {
            var response = {
                productListResponse: {
                    mortgageList: [{
                        "currentBalance": 1887.72
                    }],
                    responseHeader: {
                        status: 1,
                        currentTimestamp: "2011-10-01T13:58:33.104+0530",
                        nonce: "2175d8662534e58e9c77ca35def779f7"
                    }
                }
            }

            var accountListObj = App.api_accounts._buildAccountList(response.productListResponse.mortgageList, '');

            expect(accountListObj.totalBalance).toEqual('1887.72');
            expect(accountListObj.list[0] instanceof App.OweAccount).toBeTruthy();
        });
    });

});